﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ExportToVis.CApExportToVisViewModel
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.ComponentModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.ExportToVis;

public class CApExportToVisViewModel : INotifyPropertyChanged
{
  private string m_output = "";
  private bool m_canExecute;
  private ITxOperation m_operation;
  public bool m_isOnRuntime;
  public string m_filename;

  public CApExportToVisViewModel()
  {
    this.CanExecute = this.m_canExecute;
    this.InitFileName();
    this.Output = TxApplication.SystemRootDirectory;
  }

  public string Output
  {
    get => this.m_output;
    set
    {
      this.m_output = value;
      this.OnPropertyChanged(new PropertyChangedEventArgs(nameof (Output)));
    }
  }

  public bool CanExecute
  {
    get => this.m_canExecute;
    set
    {
      this.m_canExecute = value;
      this.OnPropertyChanged(new PropertyChangedEventArgs(nameof (CanExecute)));
    }
  }

  public ITxOperation Operation
  {
    get => this.m_operation;
    set
    {
      this.m_operation = value;
      if (this.m_isOnRuntime)
        return;
      this.OnPropertyChanged(new PropertyChangedEventArgs(nameof (Operation)));
    }
  }

  public event PropertyChangedEventHandler PropertyChanged;

  public void OnPropertyChanged(PropertyChangedEventArgs e)
  {
    if (this.PropertyChanged == null)
      return;
    this.PropertyChanged((object) this, e);
  }

  public void InitFileName()
  {
    if (TxApplication.ActiveDocument.CurrentStudy != null)
      this.m_filename = TxApplication.ActiveDocument.CurrentStudy.Caption + "_VisView";
    else if (TxTcUtilities.IsTcOnlinePlatform)
      this.m_filename = TxApplication.ActiveDocument.PhysicalRoot.Name + "_VisView";
    else
      this.m_filename = "VisView";
  }

  public bool BrowseOutput()
  {
    using (TxFolderBrowserDialog folderBrowserDialog = new TxFolderBrowserDialog())
    {
      if (!string.IsNullOrEmpty(this.Output))
        folderBrowserDialog.InitialFolder = this.Output;
      if (folderBrowserDialog.ShowDialog() != 1)
        return false;
      this.Output = folderBrowserDialog.SelectedFolder;
      return true;
    }
  }

  public void CheckCanExecute() => this.CanExecute = this.Output != "" && this.Operation != null;
}
